//导入request.js
import request from '@/utils/request.js'

export const registerService = (registerData) => {
    //借助于urlSearchParams完成传递
    var params = new URLSearchParams()
    for (let key in registerData) {
        params.append(key, registerData[key])
    }
    return request.post('/user/register', params)
}

//提供调用登录接口的函数
export const userLoginService = (loginData) =>{
    const params = new URLSearchParams();
    for(let key in loginData){
        params.append(key, loginData[key]);
    }
    return request.post('/user/login', params)
}

export const checkAdminService = (value) =>{
    return request.get('/user/register/checkAdmin', {params:{value:value}})
}

//获取用户详细信息
export const userInfoService = (userId) =>{
    // console.log(userId)
    return request.get('/user/userInfo', {params:{id:userId}})
}


//修改个人信息
export const userInfoUpdateService = (userData) =>{
    return request.put('/user/update', userData)
}

//修改密码
export const userResetPasswordService = (pwdData) =>{
    // console.log(pwdData)
    return request.patch('/user/resetPassword', pwdData)
}

//删除用户
export const deleteUserService = (delData) =>{
    return request.delete('/user', {params: delData})
}

//根据id删除用户
export const deleteUserByIdService = (delId) =>{
    // console.log(delId)
    return request.delete('/user/deleteById', { params: { id: delId } })
}

//用户列表
export const userListService = () =>{
    return request.get('/user/list')
}

//分页显示列表
export const userPageService = (params) =>{
    return request.get('/user/page', {params: params})
}


//修改头像
export const userAvatarUpdateService = (avatarUrl) => {
    const params = new URLSearchParams();
    params.append('avatarUrl', avatarUrl)
    return request.patch('/user/updateAvatar', params)
}
